﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Inventory._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>

    <script type="text/javascript" src="view/media/js/jquery-1.10.1.min.js"></script>

    <script type="text/javascript">
     $(function(){  
            $.getJSON("Default.aspx?action=getJson", function(json){  
                var trArr=[];  
                $(json).each(function(index, value){  
                    trArr.push("<tr><td>"+value.id+"</td><td>"+value.name+"</td></tr>");  
                });  
                $("#tbodyList").append(trArr.join(""));  
            });
            
            $.TableToJson=function(tableid) {
                var txt = "[";
                var table = document.getElementById(tableid);
                var row = table.getElementsByTagName("tr");
                var col = $("#"+tableid+" thead tr th");
                for (var j = 1; j < row.length; j++) {
                    var r = "{";
                    for (var i = 0; i < col.length; i++) {
                        var tds = row[j].getElementsByTagName("td");
                        r += "\"" + col.eq(i).attr("fieldname") + "\"\:\"" + $.trim(tds[i].innerHTML) + "\",";
                    }
                    r = r.substring(0, r.length - 1)
                    r += "},";
                    txt += r;
                }
                txt = txt.substring(0, txt.length - 1);
                txt += "]";
                return txt;
            }
        }); 

    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table id="tbodyList">
            <thead>
                <tr>
                    <th fieldname="id">
                        代码
                    </th>
                    <th fieldname="name">
                        名称
                    </th>
                </tr>
            </thead>
        </table>
    </div>
    <input type="button" />
    </form>
</body>
<script type="text/javascript">
$(function(){
    $("input[type='button']").click(function(){
    var aa=$.TableToJson("tbodyList");
        alert(aa);
    })
});
</script>
</html>
